using System;
using System.Globalization;

namespace jSLCore.Client.Presentation.jBinding.BaseConverters
{
    public class jCurrencyConverter :jChainConverter
    {

        public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if(value is decimal)
            {
                return ((decimal)value).ToString("c",culture);
            }
            return value;
        }

        public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if(value is string)
            {
                decimal val;
                if(decimal.TryParse((string) value,NumberStyles.Any,culture , out val))
                {
                    return val;
                }
            }
            return value;
        }

        public override Type ThisType
        {
            get { return typeof (decimal); }
        }
    }
}